Skip to content

Fix hydration mismatches by moving localStorage reads to useEffect#139

Merged
jamespepper81 merged 4 commits into
devfrom
main
Nov 19, 2025
Merged

Fix hydration mismatches by moving localStorage reads to useEffect#139
jamespepper81 merged 4 commits into
devfrom
main

Conversation

@jamespepper81

Copy link
Copy Markdown
Contributor

This pull request makes improvements to both the ESLint configuration and the RootLayout component to better support legitimate React hydration patterns and cookie consent handling. The main changes involve updating state initialization logic for analytics consent and adjusting linting rules to accommodate these patterns.

ESLint configuration updates:

  • Disabled the react-hooks/set-state-in-effect rule to allow calling setState inside useEffect, which is needed for proper hydration and client-side initialization patterns.

React hydration and consent logic improvements:

  • Refactored the initialization of the analyticsAllowed state in RootLayout (layout.tsx) to use useEffect for reading from localStorage after the component mounts, instead of initializing it directly in the state hook. This ensures compatibility with server-side rendering and avoids hydration mismatches.
  • Removed the unnecessary suppressHydrationWarning attribute from the <html> tag, as hydration is now handled correctly.

jamespepper81 and others added 4 commits November 19, 2025 09:42
Fix for Unused variable, import, function or class
Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com>
…ch-issue

Fix hydration mismatches by moving localStorage reads to useEffect
@jamespepper81 jamespepper81 merged commit 2da7518 into dev Nov 19, 2025
1 check passed
jamespepper81 added a commit that referenced this pull request Nov 19, 2025
Merge pull request #139 from BitSleuthAI/main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants